<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>酒店注册</title>
        <link rel="icon" th:href="@{/static/favicon.ico}" />
        <link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap.min.css}" />
        <link rel="stylesheet" th:href="@{/static/admin/css/main.css}" />
        <script th:src="@{/static/js/vue.min.js}"></script>
        <script th:src="@{/static/js/axios.min.js}"></script>
        <script th:src="@{/static/js/jquery-3.3.1.min.js}"></script>
        <script th:src="@{/static/bootstrap/js/bootstrap.bundle.js}"></script>
        <script th:src="@{/static/admin/js/script.js}"></script>
    </head>

    <body>
        <main>
            <div class="main">
                <div class="title-box">
                    <table style="text-align: center">
                        <thead style="color: black">
                            <tr>
                                <th :width="width[0]" scope="col">订单编号</th>
                                <th :width="width[1]" scope="col">入住客户ID</th>
                                <th :width="width[2]" scope="col">房间号</th>
                                <th :width="width[3]" scope="col">酒店名称</th>
                                <th :width="width[4]" scope="col">预订时间</th>
                                <th :width="width[5]" scope="col">操作</th>
                            </tr>
                        </thead>
                    </table>
                </div>
                <div class="table-box" th:style="|display: ${#lists.isEmpty(list) ? 'flex' : 'block'};|">
                    <h1 th:if="${#lists.isEmpty(list)}" class="display-4" style="margin: auto">暂无订房申请</h1>
                    <table class="table" style="text-align: center" th:unless="${#lists.isEmpty(list)}">
                        <tbody>
                            <tr th:each="reservation : ${list}">
                                <th th:text="${reservation.id}"></th>
                                <td th:text="${reservation.userId}"></td>
                                <td th:text="${reservation.roomId}"></td>
                                <td th:text="${reservation.hotelName}"></td>
                                <td th:text="${reservation.createTimeToString()}"></td>
                                <td style="padding: 0.4rem; width: 20%">
                                    <button class="modify" :disabled="Lock" th:@click="|JustDoIt(${reservation.id},1)|">通过</button>
                                    <button class="delete" :disabled="Lock" th:@click="|JustDoIt(${reservation.id},0)|">拒绝</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="submit-box" style="border-top: 1px solid #ccc">
                    <h5 th:text="|共${list.size}条|">共75条</h5>
                </div>
            </div>
        </main>

        <script>
            var vue = new Vue({
                el: ".main",
                data: {
                    width: [102.583, 100.781, 100.781, 469.573, 521.75, 323.865],
                    Lock: false,
                },
                methods: {
                    JustDoIt(id, status) {
                        this.Lock = true;
                        axios
                            .get(`/room/reservation/handle/${id}/${status}`)
                            .then((response) => {
                                vue.Lock = false;
                                var result = response.data;
                                if (result.code == 200) {
                                    alert(status ? "已通过该预订申请！" : "已拒绝该预订申请！");
                                    window.location.reload();
                                } else {
                                    alert(result.message);
                                }
                            })
                            .catch((error) => {
                                alert("请求出错：" + error);
                            });
                    },
                },
            });

            $(function () {
                var width = [];
                $("tbody > tr:first th, tbody > tr:first td").each(function () {
                    width.push($(this).innerWidth());
                });
                if (width.length != 0) {
                    vue.width = width;
                }
            });
        </script>
    </body>
</html>
